package linkedlist.leetcode;

import java.util.Objects;

/**
 * @author lynn
 * @date 18-12-15 上午10:31
 */
public class Solution2 {

    public ListNode removeElements(ListNode head, int val) {

        ListNode dummyHead = new ListNode(-1);
        dummyHead.next = head;

        ListNode prev = dummyHead;
        while (Objects.nonNull(prev.next)) {
            if (prev.next.val == val) {
                prev.next = prev.next.next;
            } else {
                prev = prev.next;
            }

        }
        return dummyHead.next;
    }


}
